<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-datatable [lvData]="tableData" [lvPaginator]="page" (lvSortChange)="sortChange($event)" lvSort #lvTable lvAsync>
    <thead>
        <tr>
            <th colspan="3">{{ 'common_resource_label' | i18n }}</th>
            <th colspan="1">{{ 'common_copies_label' | i18n }}</th>
        </tr>
        <tr>
            <th *ngFor="let col of columns" [lvShowFilter]="col.filter" (lvFilterChange)="filterChange($event)"
                [(lvFilters)]="col.filterMap" [lvCellKey]="col.key" lvShowCustom lvFilterCheckAll
                [lvShowSort]="col.sort">
                {{col.label}}
                <div lvCustom *ngIf="col.key === 'resourceName'">
                    <i lv-icon="lv-icon-search" [lvColorState]="true" [ngClass]="{ active: !!resourceName }" lv-popover
                        [lvPopoverContent]="nameFilterTpl" lvPopoverTheme="light" lvPopoverPosition="bottom"
                        lvPopoverTrigger="click" #sourceNamePopover="lvPopover"></i>
                </div>
                <div lvCustom *ngIf="col.key === 'resourceLocation'">
                    <i lv-icon="lv-icon-search" [lvColorState]="true" [ngClass]="{ active: !!resourceLocation }"
                        lv-popover [lvPopoverContent]="locationFilterTpl" lvPopoverTheme="light"
                        lvPopoverPosition="bottom" lvPopoverTrigger="click" #resourceLocationPopover="lvPopover"></i>
                </div>
            </th>
        </tr>
    </thead>
    <tbody>
        <ng-container *ngFor="let item of lvTable.renderData">
            <tr>
                <td>
                    <a (click)="getResourceDetail(item)" id='outerClosable' class="aui-link" lv-overflow>
                        {{ item.resourceName }}
                    </a>
                </td>
                <td>
                    <span lv-overflow>
                        {{ item.resourceLocation | nil }}
                    </span>
                </td>
                <td>
                    <aui-status [value]="item.resourceStatus" type="Resource_Status"></aui-status>
                </td>
                <td>
                    {{ item.copyCount }}
                </td>
            </tr>
        </ng-container>
    </tbody>
</lv-datatable>
<div class="aui-paginator-wrap">
    <lv-paginator [lvPageSize]="pageSize" [lvTotal]="total" [lvPageIndex]="pageIndex" #page
        (lvPageChange)="pageChange($event)" [lvPageSizeOptions]="sizeOptions" [hidden]="!total">
    </lv-paginator>
</div>


<ng-template #nameFilterTpl>
    <lv-search [(ngModel)]="resourceName" (lvSearch)="searchByName($event)" [lvFocus]="true"></lv-search>
</ng-template>


<ng-template #locationFilterTpl>
    <lv-search [(ngModel)]="resourceLocation" (lvSearch)="searchByLocation($event)" [lvFocus]="true"></lv-search>
</ng-template>